﻿using LY.DataAccess.Repository;
using LY.Entity;
using LY.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace LY.Business.ServiceImpl
{
    public class CompanydocumentService : ICompanydocumentService
    {
        CompanydocumentRepository _companydocument;
        public CompanydocumentService()
        {
            _companydocument = new CompanydocumentRepository();
        }
        //获取图片
        public List<U_Companydocument> GetCompanydocumentList(int id)
        {
            return _companydocument.GetCompanydocumentList(id);
        }
        //添加图片
        public int AddImages(List<U_Companydocument> dou)
        {
            var result = 0;
            foreach (var companydocument in dou)
            {
                result = (int)_companydocument.Insert(companydocument);
            }
            return result;
        }
        //删除附件图片
        public int DeleteImages(int id)
        {
            DeleteFile(GetDocumentListbyId(id));
            return _companydocument.DeleteImagesbyId(Convert.ToInt32(id));
        }

        private void DeleteFile(string path)
        {
            string mapPath = HttpContext.Current.Server.MapPath(path);
            if (System.IO.File.Exists(mapPath))
            {
                System.IO.File.Delete(mapPath);
            }
        }
        public string GetDocumentListbyId(int id)
        {
            return _companydocument.GetCompanydocumentListbyId(id);
        }
    }
}
